package com.xujiakai.car.maintain.domain.entity;

import com.xujiakai.car.maintain.application.service.impl.BaseDataManageService;
import com.xujiakai.car.maintain.infrastructure.mapper.DaoFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class Supplier {
    private Integer id;

    private String suppliername;

    private String contacts;

    private String phone;

    private String contactinfo;

    private String fax;

    private String mailbox;

    private String address;

    private String postcode;

    private String bankaccount;

    private String suppflag;

    @Resource
    private DaoFactory daoFactory;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getSuppliername() {
        return suppliername;
    }

    public void setSuppliername(String suppliername) {
        this.suppliername = suppliername == null ? null : suppliername.trim();
    }

    public String getContacts() {
        return contacts;
    }

    public void setContacts(String contacts) {
        this.contacts = contacts == null ? null : contacts.trim();
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone == null ? null : phone.trim();
    }

    public String getContactinfo() {
        return contactinfo;
    }

    public void setContactinfo(String contactinfo) {
        this.contactinfo = contactinfo == null ? null : contactinfo.trim();
    }

    public String getFax() {
        return fax;
    }

    public void setFax(String fax) {
        this.fax = fax == null ? null : fax.trim();
    }

    public String getMailbox() {
        return mailbox;
    }

    public void setMailbox(String mailbox) {
        this.mailbox = mailbox == null ? null : mailbox.trim();
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address == null ? null : address.trim();
    }

    public String getPostcode() {
        return postcode;
    }

    public void setPostcode(String postcode) {
        this.postcode = postcode == null ? null : postcode.trim();
    }

    public String getBankaccount() {
        return bankaccount;
    }

    public void setBankaccount(String bankaccount) {
        this.bankaccount = bankaccount == null ? null : bankaccount.trim();
    }

    public String getSuppflag() {
        return suppflag;
    }

    public void setSuppflag(String suppflag) {
        this.suppflag = suppflag == null ? null : suppflag.trim();
    }

    public boolean modifySupplier(com.xujiakai.car.maintain.domain.dto.SupplierDTO supplier, String type) {
        boolean flag = false;
        if (supplier != null && org.apache.commons.lang.StringUtils.isNotBlank(type)) {
            try {
                if ("C".equals(type)) {// 添加用户的信息
                    supplier.setSuppflag("1");
                    flag = daoFactory.getSupplierMapper().insertSelective(supplier) > 0;
                } else if ("U".equals(type)) {// 修改用户的信息
                    flag = daoFactory.getSupplierMapper().updateByPrimaryKeySelective(supplier) > 0;
                } else if ("D".equals(type)) {// 删除用户的信息(flag=0)
                    com.xujiakai.car.maintain.domain.dto.SupplierDTO sp = daoFactory.getSupplierMapper().selectByPrimaryKey(supplier.getId());
                    if (sp != null) {
                        sp.setSuppflag(supplier.getSuppflag());
                        flag = daoFactory.getSupplierMapper().updateByPrimaryKeySelective(sp) > 0;
                    }
                }
            } catch (Exception e) {
                BaseDataManageService.logger.error("修改供应商信息失败!");
            }
        }
        return flag;
    }

    public List<com.xujiakai.car.maintain.domain.dto.SupplierDTO> queryAllSupplier() {
        return daoFactory.getSupplierMapper().selectAllSupplier(null, null, null, null);
    }


}